﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using Utils;
using AlipayClass;
using tenpay;

public partial class order_tenpay_callback : BasePage
{


    private Maticsoft.BLL.Order order = new Maticsoft.BLL.Order();
    private Maticsoft.Model.Order orderlist = new Maticsoft.Model.Order();
    private Maticsoft.Model.Pay paylist = new Maticsoft.Model.Pay();
    private Maticsoft.Model.System system = new Maticsoft.Model.System();
    private Maticsoft.BLL.System systems = new Maticsoft.BLL.System();
    private Maticsoft.BLL.UserInfo user = new Maticsoft.BLL.UserInfo();
    private Maticsoft.Model.UserInfo userList = new Maticsoft.Model.UserInfo();

    // Methods
    protected void getResult()
    {
        this.system = this.systems.GetModel(1);
        string key = "";
        if (this.system != null)
        {
            key = this.system.tenpaysec.Trim();
        }
        PayResponseHandler handler = new PayResponseHandler(this.Context);
        handler.setKey(key);
        if (handler.isTenpaySign())
        {
            string str2 = handler.getParameter("bargainor_id");
            string str3 = handler.getParameter("transaction_id");
            string str4 = handler.getParameter("total_fee");
            string str5 = handler.getParameter("pay_result");
            if ("0".Equals(str5))
            {
                string orderid = handler.getParameter("sp_billno");
                string str7 = handler.getParameter("total_fee");
                if (str7 != "")
                {
                    object obj4;
                    Maticsoft.BLL.Order.Updateorder(orderid, (Convert.ToDecimal(str7) / 100M).ToString(), "tenpay");
                    string path = base.Server.MapPath("~/tenpaylog");
                    object obj2 = new object();
                    object obj3 = new object();
                    lock ((obj4 = obj2))
                    {
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                    }
                    string str9 = base.Server.MapPath("~/tenpaylog/" + DateTime.Now.ToString("yyyyMMdd") + ".config");
                    StringBuilder builder = new StringBuilder();
                    for (int i = 0; i < base.Request.QueryString.Count; i++)
                    {
                        builder.Append("&" + base.Request.QueryString.Keys[i] + "=" + base.Request.QueryString[i]);
                    }
                    lock ((obj4 = obj3))
                    {
                        File.AppendAllText(str9, builder.ToString());
                    }
                }
                handler.doShow(base.WWWprefix + "order/success.aspx?id=" + orderid);
            }
            else
            {
                base.Response.Write("支付失败");
            }
        }
        else
        {
            base.Response.Write("认证签名失败");
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.getResult();
    }

}